#include <bits/stdc++.h>
#define MAX 200002
#define ull unsigned long long
using namespace std;
const int e = 200002; // i=(n-j*j)/2;
const int ie = (e - 1) / 2;
const int je = int(sqrt(e - 2));
int t, p, n;
ull ans[100001][150], result;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // clock_t haha;
    // haha=clock();
    freopen("moon.in", "r", stdin);
    freopen("moon.out", "w", stdout);
    cin >> t >> p;
    for (int i = 1; i < ie; i++)
        ans[i][1] = 1;
    for (int j = 1; j < je; j++)
            ans[0][j] = 1;
    for (int j = 2; j < je; j++)
        for (int i = 1; i < ((e - j * j) >> 1); i++)
            ans[i][j] = (ans[i][j - 1] + (i-j<0?0:ans[i - j][j])) % p;
    while (t--)
    {
        cin >> n;
        result = 0;
        for (int j = (n & 1) ? 1 : 2; j * j <= n; j += 2)
            result = (result + ans[(n - j * j) >> 1][j]) % p;
        cout << result << '\n';
    }
    // clock_t ed;
    // ed=clock();
    // ed-=haha;
    // ed+=1;
}